import java.util.Date;
import java.util.logging.*;

/**
 * This class will format logs to HTML files.
 * @author Team 1: ThunderDragon
 */

public class ThunderDragonHtmlFormatter extends Formatter{
	
	public String format(LogRecord record){
		StringBuffer buffer = new StringBuffer(1000);
		
		if(record.getLevel().intValue() >= Level.WARNING.intValue()){
			//If the level is higher than WARNING, go ahead and bold it.
			buffer.append("<b>");
			buffer.append(record.getLevel().intValue());
			buffer.append("<b>");
		}
		
		else {
			// It's lower than the WARNING level, but still get the level.
			buffer.append(record.getLevel().intValue());
		}
		
        buffer.append(' '); //Space.
        buffer.append(record.getMillis()); //Get local program run-time.
        buffer.append(' ');//Space.
        buffer.append(formatMessage(record));//Formatted message of the log record.
        buffer.append('\n');//New line.
        return buffer.toString();//Return the formatted contents of the log.
		
	}
	
	//Gets called when a handler is created.
	public String getHead(Handler handler){
        return "<HTML><HEAD>" + (new Date()) + "</HEAD><BODY><PRE>\n";
	}
	
	//Gets called when a handler is closed.
	public String getTail(Handler handler){
        return "</PRE></BODY></HTML>\n";
	}

	@Override
	public String toString() {
		return "ThunderDragonHtmlFormatter [getClass()=" + getClass()
				+ ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}

}
